package engine.collider;

public class Intersector {

	private Intersector() {};
	
	public static boolean intersectsBoxSphere(double[] min, double[] max, double[] center, double radius) {
		double distance = 0;
		for(int i = 0; i < 3; i++) {
			if(center[i] < min[i]) {
				distance += (center[i] - min[i]) * (center[i] - min[i]);
			} else if(center[i] > max[i]) {
				distance += (center[i] - max[i]) * (center[i] - max[i]);
			}
		}
		
		if(distance < radius * radius) {
			return true;
		} else {
			return false;
		}
	}
	
	public static boolean intersectsBoxSphere(double[] min, double boxSize, double[] center, double radius) {
		double distance = 0;
		for(int i = 0; i < 3; i++) {
			if(center[i] < min[i]) {
				distance += (center[i] - min[i]) * (center[i] - min[i]);
			} else if(center[i] > min[i] + boxSize) {
				distance += (center[i] - min[i] + boxSize) * (center[i] - min[i] + boxSize);
			}
		}
		
		if(distance < radius * radius) {
			return true;
		} else {
			return false;
		}
	}
}
